import 'package:flutter/material.dart';
import 'package:flutter_widget/custom/custom_appbar.dart';

// ignore: must_be_immutable
class ChoosePage extends StatefulWidget {
  String name;
  ChoosePage({Key? key, required this.name}) : super(key: key);

  @override
  // ignore: no_logic_in_create_state
  _ChoosePageState createState() => _ChoosePageState();
}

class _ChoosePageState extends State<ChoosePage> {
  bool _checkbox = false;
  int _radio = 0;
  double _slider = 0.0;
  bool _switch = false;
  bool _checkboxListTitle = false;
  bool _switchListTile = false;
  int _radioListTitle = 0;
  void handleRadioValue(v) {
    setState(() {
      _radio = v!;
    });
  }

  void handleRadioListTitleValue(v) {
    setState(() {
      _radioListTitle = v;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: CustomAppbar(widget.name, Theme.of(context).primaryColor),
      body: Center(
        child: Column(
          children: [
            Checkbox(
                value: _checkbox,
                activeColor: Colors.purple,
                onChanged: (v) {
                  setState(() {
                    _checkbox = v!;
                  });
                }),
            Switch(
                value: _switch,
                onChanged: (v) {
                  setState(() {
                    _switch = v;
                  });
                }),
            SwitchListTile(
              value: _switchListTile,
              onChanged: (v) {
                setState(() {
                  _switchListTile = v;
                });
              },
              title: const Text('SwitchListTile 标题'),
              subtitle: const Text('SwitchListTile 副标题'),
              secondary: Icon(
                  _switchListTile ? Icons.visibility : Icons.visibility_off),
              selected: _switchListTile,
            ),
            CheckboxListTile(
              value: _checkboxListTitle,
              onChanged: (v) {
                setState(() {
                  _checkboxListTitle = v!;
                });
              },
              title: const Text('CheckboxListTile 标题'),
              subtitle: const Text('CheckboxListTile 副标题'),
              secondary: const Icon(Icons.bookmark),
              selected: _checkboxListTitle,
            ),
            Row(
              children: [
                Radio(
                    value: 0,
                    groupValue: _radio,
                    activeColor: Theme.of(context).primaryColor,
                    onChanged: handleRadioValue),
                Radio(
                    value: 1,
                    groupValue: _radio,
                    activeColor: Theme.of(context).primaryColor,
                    onChanged: handleRadioValue),
              ],
            ),
            Text('groupValue的值为:$_radioListTitle'),
            RadioListTile(
              value: 0,
              groupValue: _radioListTitle,
              onChanged: handleRadioListTitleValue,
              title: const Text('RadioListTile 标题A'),
              subtitle: const Text('RadioListTile 副标题A'),
              secondary: const Icon(Icons.filter_1),
              selected: _radioListTitle == 0,
            ),
            RadioListTile(
              value: 1,
              groupValue: _radioListTitle,
              onChanged: handleRadioListTitleValue,
              title: const Text('RadioListTile 标题B'),
              subtitle: const Text('RadioListTile 副标题B'),
              secondary: const Icon(Icons.filter_2),
              selected: _radioListTitle == 1,
            ),
            Slider(
                value: _slider,
                activeColor: Theme.of(context).primaryColor,
                inactiveColor: Colors.grey,
                min: 0.0,
                max: 1.0,
                divisions: 10,
                label: '${100 * _slider} %',
                onChanged: (v) {
                  setState(() {
                    _slider = v;
                  });
                }),
          ],
        ),
      ),
    );
  }
}
